#include <iostream>
#include <string>
#include <vector>
#include <cmath>

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<std::string> a;
    std::string temp = "";
    for (char c : input) {
        if (c == ' ') {
            a.push_back(temp);
            temp = "";
        } else {
            temp += c;
        }
    }
    a.push_back(temp);

    std::string i = "";
    int f = 1;
    int w = 0;
    for (int j = 0; j < 3; j++) {
        if (f == 1) {
            f = 1;
        }
    }
    if (f == 1) {
        for (std::string e : a) {
            if (e == "zero") {
                i += "0";
            } else if (e == "one") {
                i += "1";
            } else if (e == "two") {
                i += "2";
            } else if (e == "three") {
                i += "3";
            } else if (e == "four") {
                i += "4";
            } else if (e == "five") {
                i += "5";
            } else if (e == "six") {
                i += "6";
            } else if (e == "seven") {
                i += "7";
            } else if (e == "eight") {
                i += "8";
            } else if (e == "nine") {
                i += "9";
            } else {
                std::cout << "Wrong input" << std::endl;
                f = 0;
                break;
            }
            w += 1;
        }
    }
    if (f == 1 && w != 3) {
        std::cout << "Wrong input" << std::endl;
        f = 0;
    }
    int num = std::stoi(i);

    int midd = 0;
    int p = 0;
    int h = 2;

    for (int k = 1; k < 1000; k++) {
        if (f == 1) {
            p = 0;
            for (int m = 2; m <= (k / 2) + 1; m++) {
                if (k % m == 0) {
                    h = 0;
                    p = 1;
                    break;
                }
            }
            if (p == 0) {
                h = 1;
            }
            if (std::abs(num - midd) > std::abs(num - k) && h == 1 && std::abs(num - midd) > std::abs(num - k)) {
                midd = k;
            }
        }
    }
    if (f == 1) {
        std::cout << midd << std::endl;
    }

    return 0;
}

